#include "SensorParameter.h"
#include <glm/glm.hpp>

SensorParameter::SensorParameter () : frameWidth (0), frameHeight (0),
		frameDepth (0), frameHFOV (0), frameVFOV (0),frameSize (0),
		depthPixelWidth (0), rgbPixelWidth (0), frameVFOVAngle (0),
		frameHFOVAngle (0) {}

SensorParameter::~SensorParameter () {}

void SensorParameter::writeTo (std::ofstream& outStream) const
{
	outStream.write ((char*)&frameWidth, sizeof (frameWidth));
	outStream.write ((char*)&frameHeight, sizeof (frameHeight));
	outStream.write ((char*)&frameDepth, sizeof (frameDepth));
	outStream.write ((char*)&frameHFOV, sizeof (frameHFOV));
	outStream.write ((char*)&frameVFOV, sizeof (frameVFOV));
	outStream.write ((char*)&frameSize, sizeof (frameSize));
	outStream.write ((char*)&depthPixelWidth, sizeof (depthPixelWidth));
	outStream.write ((char*)&rgbPixelWidth, sizeof (rgbPixelWidth));
}

void SensorParameter::readFrom (std::ifstream& inStream)
{
	inStream.read ((char*)&frameWidth, sizeof (frameWidth));
	inStream.read ((char*)&frameHeight, sizeof (frameHeight));
	inStream.read ((char*)&frameDepth, sizeof (frameDepth));
	inStream.read ((char*)&frameHFOV, sizeof (frameHFOV));
	inStream.read ((char*)&frameVFOV, sizeof (frameVFOV));
	inStream.read ((char*)&frameSize, sizeof (frameSize));
	inStream.read ((char*)&depthPixelWidth, sizeof (depthPixelWidth));
	inStream.read ((char*)&rgbPixelWidth, sizeof (rgbPixelWidth));
	frameVFOVAngle = glm::tan (frameVFOV / 2);
	frameHFOVAngle = glm::tan (frameHFOV / 2);
}